/*
 *  maskGenerate.c
 *  Ball and Plate
 *
 *  Created by Kenn Sebesta on 2007-11-22.
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
 *
 */

#include "maskGenerate.h"
#include <OpenCV/OpenCV.h>
#include <iostream>

IplImage* maskGenerate( double ballDia, double camCal )
{
	IplImage* maskImage;
	double ballRadPix, t;
	int maskSize;
	
	// Determines maskImage size based on the resolution
	ballRadPix=camCal*ballDia/2;
	maskSize=(int)round(ballRadPix)*2+1;
	
	// Creates the maskImage prototype
	maskImage = cvCreateImage(cvSize(maskSize, maskSize),  IPL_DEPTH_8U,1);
	cvZero(maskImage);
	
	//Creates the circle representing the ball
	for (t=0;t<=6.27;t+=0.01) {
		cvSetReal2D( maskImage, (int)round((maskSize-1)/2+ballRadPix*cos(t)), (int)round((maskSize-1)/2+ballRadPix*sin(t)), 255 );	
	}
	
	return maskImage;
}
